import request from "@/utils/request";

/**
 * 分页查询轮播图
 */
export async function pageInformations(params) {
  const res = await request.get("/information/page", { params });
  if (res.data.code === 200) {
    return res.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 查询轮播图列表
 */
export async function listInformations(params) {
  const res = await request.get("/information", {
    params,
  });
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 根据id查询用户
 */
export async function getInformation(id) {
  const res = await request.get("/information/" + id);
  if (res.data.code === 200 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 添加轮播图
 */
export async function addInformation(data) {
  const res = await request.post("/information", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 修改轮播图
 */
export async function updateInformation(data) {
  const res = await request.put("/information/" + data.id, data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
/**
 * 修改轮播图状态
 */
export async function updateInformationStatus(data) {
  const res = await request.put("/information/status", data);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 删除轮播图
 */
export async function removeInformation(id) {
  const res = await request.delete("/information/" + id);
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}

/**
 * 批量删除轮播图
 */
export async function removeInformations(data) {
  const res = await request.delete("/information/batch", {
    data,
  });
  if (res.data.code === 200) {
    return res.data.msg;
  }
  return Promise.reject(new Error(res.data.msg));
}
